package xyz.keyon.service.impl;

import xyz.keyon.bean.Student;
import xyz.keyon.dao.IStudentDao;
import xyz.keyon.dao.impl.StudentDaoImpl;
import xyz.keyon.service.IStudentService;

import java.util.List;

public class StudentServiceImpl implements IStudentService {
    IStudentDao dao = new StudentDaoImpl();
    @Override
    public boolean addStudent(Student student) {
        //如果该学号已存在
        if(dao.queryStudentBySno(student.getSno()) != null){
            return false;
        } else {
            return dao.addStudent(student);
        }
    }

    @Override
    public boolean deleteStudent(String Sno) {
        //如果该学号不存在
        if(dao.queryStudentBySno(Sno) == null) {
            return false;
        } else {
            return dao.deleteStudentBySno(Sno);
        }
    }

    @Override
    public List<Student> queryAllStudents() {
        return dao.queryAllStudent();
    }

    @Override
    public Student queryStudentBySno(String Sno) {
        return dao.queryStudentBySno(Sno);
    }

    @Override
    public boolean updateStudentBySno(Student student) {
        //如果该学号不存在
        if(dao.queryStudentBySno(student.getSno()) == null) {
            return false;
        } else {
            return dao.updateStudentBySno(student);
        }
    }

    @Override
    public List<Student> queryStudentsByPage(int currentPage, int pageSize) {
        return dao.queryStudentsByPage(currentPage,pageSize);
    }

    @Override
    public int getTotalCount() {
        return dao.getTotalCount();
    }
}
